package com.tsxy.mall.mapper;

import com.tsxy.mall.entity.UsedBook;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface UsedBookMapper {

    @Select({"select * from used_book "})
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.INTEGER, id=true),
            @Result(column="book_sort_id", property="bookSortId", jdbcType=JdbcType.INTEGER),
            @Result(column="author", property="author", jdbcType=JdbcType.VARCHAR),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="dscp", property="dscp", jdbcType=JdbcType.VARCHAR),
            @Result(column="price", property="price", jdbcType=JdbcType.DECIMAL),
            @Result(column="version", property="version", jdbcType=JdbcType.VARCHAR),
            @Result(column="color", property="color", jdbcType=JdbcType.VARCHAR),
            @Result(column="suit", property="suit", jdbcType=JdbcType.VARCHAR),
            @Result(column="count", property="count", jdbcType=JdbcType.INTEGER),
            @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
            @Result(column = "id",property = "fileUrl",
                    many = @Many(select = "com.tsxy.mall.mapper.UsedBookPictureRelationMapper.getByUsedBookId"))
    })
    List<UsedBook> getAll();

    @Select({"select * from used_book where id = #{id}"})
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.INTEGER, id=true),
            @Result(column="book_sort_id", property="bookSortId", jdbcType=JdbcType.INTEGER),
            @Result(column="author", property="author", jdbcType=JdbcType.VARCHAR),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="dscp", property="dscp", jdbcType=JdbcType.VARCHAR),
            @Result(column="price", property="price", jdbcType=JdbcType.DECIMAL),
            @Result(column="discount", property="disCount", jdbcType=JdbcType.INTEGER),
            @Result(column="version", property="version", jdbcType=JdbcType.VARCHAR),
            @Result(column="color", property="color", jdbcType=JdbcType.VARCHAR),
            @Result(column="suit", property="suit", jdbcType=JdbcType.VARCHAR),
            @Result(column="count", property="count", jdbcType=JdbcType.INTEGER),
            @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
            @Result(column = "id",property = "fileUrl",
                    many = @Many(select = "com.tsxy.mall.mapper.UsedBookPictureRelationMapper.getByUsedBookId"))
    })
    UsedBook getById(Integer id);
}
